﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GMigrate
{
    class RetryCode
    {
        static public void Run(int tries, Action code)
        {
            bool success = false;
            while (!success)
            {
                try
                {
                    code();
                    success = true;
                }
                catch (Exception ex)
                {
                    tries--;
                    if (tries == 0)
                        throw ex;
                }
            }
        }

        static public void Run(int tries, Action<int> code)
        {
            bool success = false;
            while (!success)
            {
                try
                {
                    code(tries);
                    success = true;
                }
                catch (Exception ex)
                {
                    tries--;
                    if (tries == 0)
                        throw ex;
                }
            }
        }
    }
}
